/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-02-04
 * Time: 22:26
 */
class Solution6 {
    public boolean validPalindrome(String s) {
        int n = s.length();
        int left = 0 , right = n - 1;
        while(left < right){
            char ch1 = s.charAt(left);
            char ch2 = s.charAt(right);

            if(ch1 == ch2){
                left++;
                right--;
            }else{
                break;
            }
        }
        boolean result1 =   validPalindrome2(s,left+1,right);
        boolean result2 =   validPalindrome2(s,left,right-1);
        if(result1 == false && result2 == false){return false;}
        return true;


    }
    public boolean validPalindrome2(String s,int left,int right){
        while(left < right){
            char ch1 = s.charAt(left);
            char ch2 = s.charAt(right);

            if(ch1 == ch2){
                left++;
                right--;
            }else{
                return false;
            }
        }
        return true;
    }

}
public class Test6 {
}
